git rebase -iの使い方
おかしなコミットが紛れ込んだのでそのコミットをなかったことにしつつ、変更点はローカルに戻してたい
code:memo
$ (main)> git rebase -i HEAD~3
ここで該当コミットをeditにする
code:memo
Stopped at c7661ce... chore(.gitignore): resolve merge conflict
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
editに↓箇所で止まるので、該当コミットをgit reset --mixed HEAD^で取り消しつつ、ステージング上に残す
code:memo
(main|REBASE-i 1/3)> git reset --mixed HEAD^
Unstaged changes after reset:
M .claude/settings.local.json
M Gemfile
M Gemfile.lock
M package-lock.json
M package.json
code:memo
(main|REBASE-i 1/3)> git rebase --skip
ログ
code:memo
(main)> git rebase -i HEAD~3
Stopped at c7661ce... chore(.gitignore): resolve merge conflict
You can amend the commit now, with
git commit --amend
Once you are satisfied with your changes, run
git rebase --continue
(main|REBASE-i 1/3)> git rebase --continue
You must edit all merge conflicts and then
mark them as resolved using git add
(main|REBASE-i 1/3) 1> git st .
interactive rebase in progress; onto c99031f
Last command done (1 command done):
edit c7661ce chore(.gitignore): resolve merge conflict
Next commands to do (2 remaining commands):
pick 5d76226 refactor(dev): simplify logs command to delegate options to tail
pick e9b64db docs(worktree): improve git worktree workflow documentation
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch 'main' on 'c99031f'.
(Once your working directory is clean, run "git rebase --continue")
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .claude/settings.local.json
modified: Gemfile
modified: Gemfile.lock
modified: package-lock.json
modified: package.json
Untracked files:
(use "git add <file>..." to include in what will be committed)
.claude/commands/
analyze_hub_nodes.rb
....
(省略)
(main|REBASE-i 1/3)> git rebase --continue
You must edit all merge conflicts and then
mark them as resolved using git add
(main|REBASE-i 1/3) 1> git add .gitignore
(main|REBASE-i 1/3)> git st .
interactive rebase in progress; onto c99031f
Last command done (1 command done):
edit c7661ce chore(.gitignore): resolve merge conflict
Next commands to do (2 remaining commands):
pick 5d76226 refactor(dev): simplify logs command to delegate options to tail
pick e9b64db docs(worktree): improve git worktree workflow documentation
(use "git rebase --edit-todo" to view and edit)
You are currently splitting a commit while rebasing branch 'main' on 'c99031f'.
(Once your working directory is clean, run "git rebase --continue")
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .claude/settings.local.json
modified: Gemfile
modified: Gemfile.lock
modified: package-lock.json
modified: package.json
Untracked files:
(use "git add <file>..." to include in what will be committed)
.claude/commands/
analyze_hub_nodes.rb
....
(省略)
# git addしてみるが変化なし
(main|REBASE-i 1/3)> git status .gitignore
interactive rebase in progress; onto c99031f
Last command done (1 command done):
edit c7661ce chore(.gitignore): resolve merge conflict
Next commands to do (2 remaining commands):
pick 5d76226 refactor(dev): simplify logs command to delegate options to tail
pick e9b64db docs(worktree): improve git worktree workflow documentation
(use "git rebase --edit-todo" to view and edit)
You are currently editing a commit while rebasing branch 'main' on 'c99031f'.
(use "git commit --amend" to amend the current commit)
(use "git rebase --continue" once you are satisfied with your changes)
nothing to commit, working tree clean
# マージコンフリクト箇所なし
pogin503@DESKTOP-66Q50RC ~/w/link-ref (main|REBASE-i 1/3)> vim .gitignore
# ChatGPTに聞くとgit rebase --skipをして該当コミットを飛ばせばよいとのこと
pogin503@DESKTOP-66Q50RC ~/w/link-ref (main|REBASE-i 1/3)> git rebase --skip
Successfully rebased and updated refs/heads/main.
確認用
Q. git rebase -iの使い方
メモ
あのコミットをなかった事に。git rebase -i の使い方 - karakaram-blog
#Git